tenacious-fetch
Tiny fetch API wrapper to add support for retries with linear & exponential backoff and timeouts
Table of Contents
Install
This project uses node and npm.
$ npm install tenacious-fetch
$
$ yarn add tenacious-fetch
Usage
import tenaciousFetch from 'tenacious-fetch'
const url = 'https://jsonplaceholder.typicode.com/posts/1'
const normalFetchConfig = {
method: 'GET',
headers: {
"Content-Type": "application/json charset=UTF-8"
},
}
const additionalTenaciousFetchConfig = {
fetcher: window.fetch,
retries: 3,
retryDelay: 1000 * 3,
onRetry: ({retriesLeft, retryDelay, response}) => console.log(retriesLeft, retryDelay, response),
retryStatus = [],
retryOnFatalError = true
timeout = 1000 * 15,
factor: .5
}
const config = Object.assign({}, normalFetchConfig, additionalTenaciousFetchConfig)
tenaciousFetch(url, config).then(console.log).catch(console.error)
Contribute
- Fork it and create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
MIT